/*
 * ConclusionJPanel.java
 *
 * Created on 16.05.2009, 20:52:48
 */

package morenoapp.components.conclusion;

import java.awt.Desktop.Action;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileOutputStream;
import morenoapp.MorenoApp;
import morenoapp.model.listeners.MorenoModelAdapter;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

/**
 * 
 * @author dmitry.mamonov
 */
public class ConclusionMainJPanel extends javax.swing.JPanel {

    /** Creates new form ConclusionJPanel */
    public ConclusionMainJPanel() {
        initComponents();
        jButtonExportConclusion.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                actionExportConclusion();
            }
        });
        MorenoApp.getModel().addModelListener(new MorenoModelAdapter(){
            @Override
            public void onWholeModelChanged() {
                firePropertyChange("modelConclusion", null, getModelConclusion()); //NOI18N
            }
        });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        jLabelConclusion = new javax.swing.JLabel();
        jScrollPaneConclusion = new javax.swing.JScrollPane();
        jTextAreaConclusion = new javax.swing.JTextArea();
        jButtonExportConclusion = new javax.swing.JButton();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(ConclusionMainJPanel.class);
        jLabelConclusion.setText(resourceMap.getString("jLabelConclusion.text")); // NOI18N
        jLabelConclusion.setName("jLabelConclusion"); // NOI18N

        jScrollPaneConclusion.setName("jScrollPaneConclusion"); // NOI18N

        jTextAreaConclusion.setColumns(20);
        jTextAreaConclusion.setFont(resourceMap.getFont("jTextAreaConclusion.font")); // NOI18N
        jTextAreaConclusion.setRows(5);
        jTextAreaConclusion.setName("jTextAreaConclusion"); // NOI18N

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${modelConclusion}"), jTextAreaConclusion, org.jdesktop.beansbinding.BeanProperty.create("text"));
        bindingGroup.addBinding(binding);

        jScrollPaneConclusion.setViewportView(jTextAreaConclusion);

        jButtonExportConclusion.setIcon(resourceMap.getIcon("jButtonExportConclusion.icon")); // NOI18N
        jButtonExportConclusion.setText(resourceMap.getString("jButtonExportConclusion.text")); // NOI18N
        jButtonExportConclusion.setName("jButtonExportConclusion"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPaneConclusion, javax.swing.GroupLayout.DEFAULT_SIZE, 507, Short.MAX_VALUE)
                    .addComponent(jLabelConclusion)
                    .addComponent(jButtonExportConclusion, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelConclusion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPaneConclusion, javax.swing.GroupLayout.DEFAULT_SIZE, 342, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonExportConclusion)
                .addContainerGap())
        );

        bindingGroup.bind();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonExportConclusion;
    private javax.swing.JLabel jLabelConclusion;
    private javax.swing.JScrollPane jScrollPaneConclusion;
    private javax.swing.JTextArea jTextAreaConclusion;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

    public void actionExportConclusion(){
        final POIFSFileSystem poiFs = new POIFSFileSystem();
        //poiFs.

        //poiFs.writeFilesystem(new FileOutputStream("out.doc"));
    }

    public String getModelConclusion(){
        return MorenoApp.getModel().getConclusion();
    }

    public void setModelConclusion(String conclusion){
        MorenoApp.getModel().setConclusion(conclusion);
    }
}
